from configparser import ConfigParser

from conf.conf_dir import conf_dir
# 初始化类
from domain.app_info import AppInfo

cp = ConfigParser()
cp.read(r"{0}/env.ini".format(conf_dir), encoding="utf-8")

# 得到第一个section
mysql_section, host_section, email_section = cp.sections()


# 获取mysql section的option值
def get_mysql_options():
    host = cp.get(mysql_section, "host")
    port = cp.getint(mysql_section, "port")
    db = cp.get(mysql_section, "db")
    user = cp.get(mysql_section, "user")
    password = cp.get(mysql_section, "password")
    return host, port, db, user, password


# 获取host section的option值
def get_host_section() -> AppInfo:
    app_info = AppInfo()
    app_info.host = cp.get(host_section, "test_host")
    app_info.appid = cp.get(host_section, "appid")
    app_info.appkey = cp.get(host_section, "appkey")
    app_info.channel = cp.get(host_section, "channel")

    return app_info


# 获取email的option值
def get_email_section():
    From = cp.get(email_section, "From")
    to = cp.get(email_section, "to")
    subject = cp.get(email_section, "subject")
    text = cp.get(email_section, "text")
    smtp_host = cp.get(email_section, "smtp_host")
    smtp_port = cp.get(email_section, "smtp_port")
    user = cp.get(email_section, "user")
    password = cp.get(email_section, "password")
    return From, to, subject, text, smtp_host, smtp_port, user, password
